<template>
  <div>
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body @close="cancel">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="账号" prop="userName">
          <el-input v-model="form.userName" placeholder="请输入账号"/>
        </el-form-item>
        <el-form-item label="快递单号" prop="trackingNo">
          <el-input v-model="form.trackingNo" size="small" placeholder="请输入原订单号"/>
        </el-form-item>
        <el-form-item label="数量" prop="cpfrAmount">
          <el-input v-model="form.cpfrAmount" size="small" placeholder="请输入原物流单号"></el-input>
        </el-form-item>
        <el-form-item label="价格" prop="purchasePrice">
          <el-input v-model="form.purchasePrice" size="small" placeholder="请输入新物流单号"></el-input>
        </el-form-item>
        <el-form-item label="申请仓库" prop="stockPlusDeliveryId">
          <el-select v-model="form.stockPlusDeliveryId" placeholder="请选择申请仓库" clearable>
            <el-option v-for="dict in storeAddressList" :key="dict.storeAddressId" :label="dict.storeName"
                       :value="dict.storeAddressId"/>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="desp">
          <el-input v-model="form.desp" placeholder="请输入备注" type="textarea"
                    :autosize="{ minRows: 3, maxRows: 6}"/>
        </el-form-item>
        <el-form-item label="采购凭证" prop="proof">
          <image-upload v-model="form.proof" :is-show-tip="false"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  replenishment, queryXdAccount, queryStoreAddress, inventoryRequest
} from "@/api/warehouse/inventory";

export default {
  props: {
    stockPlusId: { // 库存列表id
      default: "",
      type: String
    },
    storeAddressList: { // 仓库列表
      default: [],
      type: Array
    },
    userName: { // 熊迪账号
      default: "",
      type: String
    }
  },
  data() {
    return {
      buttonLoading: false,//确定提交表单按钮loading
      title: "补充库存",
      open: true,
      form: {},
      rules: {
        userName: [{required: true, message: "账号不能为空", trigger: "blur"}],
        trackingNo: [{required: true, message: "快递单号不能为空", trigger: "blur"}],
        cpfrAmount: [{required: true, message: "数量不能为空", trigger: "blur"}],
        purchasePrice: [{required: true, message: "价格不能为空", trigger: "blur"}],
        stockPlusDeliveryId: [{required: true, message: "仓库地址不能为空", trigger: "blur"}],
        desp: [{required: true, message: "备注不能为空", trigger: "blur"}],
        proof: [{required: true, message: "采购凭证不能为空", trigger: "blur"}],
      }
    }
  },
  created() {
    this.reset()
  },
  methods: {
    // 确定提交
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.buttonLoading = true
          replenishment(this.form).then(res => {
            this.$message.success('提交成功！')
            this.cancel()
          }).finally((err) => {
            this.buttonLoading = false
          })
        }
      })
    },
    reset() {
      this.form = {
        userName: undefined,
        trackingNo: undefined,
        cpfrAmount: undefined,
        purchasePrice: undefined,
        stockPlusDeliveryId: undefined,
        desp: undefined,
        proof: undefined,
      }
      this.resetForm("form");
    },

    // 取消
    cancel(e) {
      this.$emit('close', e)
    },
  }
}
</script>

<style scoped>

</style>
